import 'package:flutter/material.dart';
import '../constant/constant.dart';

/// 自定义对话框
/// 1. 继承Dialog
/// 2. 设置构造方法
/// 3. 设置透明层
/// 4. 设置背景框
/// 5. 设置圆角背景及颜色
/// 6. 设置进度条指示器和标题

/// 加载中对话框
class Loading extends Dialog {
  /// 提示信息
  final String text;

  /// 对话框上下文
  BuildContext _context;

  /// 构造方法
  Loading({Key key, @required this.text}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // 赋值对话框上下文
    this._context = context;
    // 对话框内容
    return Material(
      type: MaterialType.transparency, // 透明类型
      child: Center(
        child: SizedBox(
          width: 120,
          height: 120,
          child: Container(
            decoration: ShapeDecoration(
                color: Colors.white,
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(10.0)))),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                CircularProgressIndicator(),
                Padding(
                    padding: const EdgeInsets.only(top: 20.0),
                    child: Text(
                      text,
                      style:
                          TextStyle(fontFamily: Constant.FONT, fontSize: 12.0),
                    ))
              ],
            ),
          ),
        ),
      ), // 保证控件居中
    ); // 透明层
  }

  /// 关闭对话框
  void dismiss() {
    // 关闭对话框
    Navigator.pop(_context);
  }
}
